package com.kgc.basicprovider.controller;


import com.kgc.basic.pojo.Provider;
import com.kgc.basic.remote.ProviderRemote;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.basicprovider.service.ProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Controller
public class ProviderController implements ProviderRemote {

    private Logger logger = LoggerFactory.getLogger(ProviderController.class);

    @Autowired
    private ProviderService providerService;


    @Override
    public ResponseMsg selectProviderByPage(@RequestBody Map<String, Object> map) {
        logger.info("ProviderController selectProviderByPage params{}", map);
        ResponseMsg responseMsg = providerService.selectProviderByPage(map);
        logger.info("ProviderController selectProviderByPage responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg insertProvider(@RequestBody Provider Provider) {
        logger.info("ProviderController insertProvider params{}", Provider);
        ResponseMsg responseMsg = providerService.insertProvider(Provider);
        logger.info("ProviderController insertProvider responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg updateProvider(@RequestBody Provider Provider) {
        logger.info("ProviderController updateProvider params{}", Provider);
        ResponseMsg responseMsg = providerService.updateProvider(Provider);
        logger.info("ProviderController updateProvider responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg deleteProvider(@RequestParam("id") int id) {
        logger.info("ProviderController deleteProvider params{}", id);
        ResponseMsg responseMsg = providerService.deleteProvider(id);
        logger.info("ProviderController deleteProvider responseMsg{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectCustomerByCode(String code) {
        logger.info("ProviderController selectCustomerByCode code:{}", code);
        ResponseMsg msg = providerService.selectProviderByCode(code);
        logger.debug("ProviderController selectCustomerByCode msg:{}", msg);
        return msg;
    }

    @Override
    public ResponseMsg selectAllSupplier() {
        logger.info("ProviderController selectAllSupplier is start...");
        ResponseMsg msg = providerService.selectAllSupplier();
        logger.debug("ProviderController selectAllSupplier msg:{}", msg);
        return msg;
    }

    @Override
    public ResponseMsg getProviderAllByData() {
        logger.info("ProviderController getProviderAllByData is start...");
        ResponseMsg msg = providerService.getProviderAllByData();
        logger.debug("ProviderController getProviderAllByData msg:{}",msg);
        return msg;
    }
}
